import { defineStore } from 'pinia'
import homeApi from '@/api/home'
import type {homeInfo,KingKongListData,IndexActivityModuleData,CategoryListData,policyDescListData,FloorListData,SwiperListData,GoodsListData} from '@/api/home'

type HomeStateData = {
  homeList:homeInfo
}

export const useHomeStore = defineStore({
  id: 'home',
  state: ():HomeStateData=>{
    return {
      homeList:{
      kingKongList:[],
      indexActivityModule:[],
      categoryList:[],
      title:'',
      policyDescList:[],
      floorList:{
        itemList:[],
        cell:[]
      },
      swiperList:[],
      goodsList:[]
      }
    }
  },
  actions: {
    async getKingkongList(){
        try {
            const res = await homeApi.getKingkongList()
            console.log(res) 
            this.homeList = res.data.data
        } catch (error) {
            
        }
    }
  },
  getters:{
    kingKongList():KingKongListData{
      return this.homeList.kingKongList || []
    },
    indexActivityModule():IndexActivityModuleData{
      return this.homeList.indexActivityModule || []
    },
    categoryList():CategoryListData{
      return this.homeList.categoryList || []
    },
    policyDescList():policyDescListData{
      return this.homeList.policyDescList || []
    },
    floorList():FloorListData{
      return this.homeList.floorList || {}
    },
    goodsList():GoodsListData{
      return this.homeList.goodsList || []
    },
    swiperList():SwiperListData{
      return this.homeList.swiperList || []
    },
  }
})